From 682002bdebf6864e9d162182af6a0ec9bb4cd0e7 Mon Sep 17 00:00:00 2001 From: Debian Science Maintainers Date: Sat, 2 Mar 2019 14:59:35 +0000 Subject: [PATCH] Make tests compatible with current numpy/scipy/pandas These issues are all within test code, i.e. should not affect users. https://github.com/statsmodels/statsmodels/commit/bb8fba9d4d9883be2991b43b29bfa3a9c3fb325a https://github.com/statsmodels/statsmodels/commit/310f91da9f07d9483965d624d76dbb7abebbd67f https://github.com/statsmodels/statsmodels/pull/4911/commits/18dcceefbfed61b0d11ae5884a9f4cea82c2edb5 https://github.com/statsmodels/statsmodels/commit/f1d5eddd44d61099a9f8f90c40c35716a8346cf7 and one new fix only needed on 32 bit Python 2 (integer data loads as int64, which gets converted to long producing factor names like C(agecat)[T.4L], which does not match C(agecat)[T.4]) Author: Kevin "bashtage" Sheppard, Peter "thequackdaddy" Quackenbush, Matthew Brett, Rebecca N. Palmer Origin: upstream (mostly) Forwarded: no Gbp-Pq: Name test_fixes.patch --- statsmodels/discrete/tests/test_constrained.py | 2 +- statsmodels/formula/tests/test_formula.py | 7 +------ statsmodels/iolib/tests/test_foreign.py | 5 ----- statsmodels/nonparametric/tests/test_kde.py | 4 ++-- statsmodels/tsa/statespace/tests/test_mlemodel.py | 2 +- statsmodels/tsa/statespace/tests/test_representation.py | 4 ++-- statsmodels/tsa/statespace/tests/test_tools.py | 2 +- 7 files changed, 8 insertions(+), 18 deletions(-) diff --git a/statsmodels/discrete/tests/test_constrained.py b/statsmodels/discrete/tests/test_constrained.py index 9a159ed..b871b10 100644 --- a/statsmodels/discrete/tests/test_constrained.py +++ b/statsmodels/discrete/tests/test_constrained.py @@ -49,7 +49,7 @@ agecat smokes deaths pyears data = pd.read_csv(StringIO(ss), delimiter='\t') data['logpyears'] = np.log(data['pyears']) - +data['agecat'] = data['agecat'].astype(int) # avoid int vs long test failure on 32 bit Python 2 class CheckPoissonConstrainedMixin(object): diff --git a/statsmodels/formula/tests/test_formula.py b/statsmodels/formula/tests/test_formula.py index 232bfca..ef4cf3b 100644 --- a/statsmodels/formula/tests/test_formula.py +++ b/statsmodels/formula/tests/test_formula.py @@ -8,7 +8,6 @@ from statsmodels.datasets.longley import load, load_pandas import numpy.testing as npt from statsmodels.tools.testing import assert_equal -from numpy.testing.utils import WarningManager longley_formula = 'TOTEMP ~ GNPDEFL + GNP + UNEMP + ARMED + POP + YEAR' @@ -34,14 +33,10 @@ class CheckFormulaOLS(object): def test_summary(self): # smoke test - warn_ctx = WarningManager() - warn_ctx.__enter__() - try: + with warnings.catch_warnings(): warnings.filterwarnings("ignore", "kurtosistest only valid for n>=20") self.model.fit().summary() - finally: - warn_ctx.__exit__() class TestFormulaPandas(CheckFormulaOLS): diff --git a/statsmodels/iolib/tests/test_foreign.py b/statsmodels/iolib/tests/test_foreign.py index c5c13bf..5bb2cdd 100644 --- a/statsmodels/iolib/tests/test_foreign.py +++ b/statsmodels/iolib/tests/test_foreign.py @@ -17,9 +17,6 @@ from statsmodels.iolib.foreign import (StataWriter, genfromdta, from statsmodels.datasets import macrodata -from statsmodels.compat.pandas import version as pandas_version -pandas_old = pandas_version < '0.9' - # Test precisions DECIMAL_4 = 4 DECIMAL_3 = 3 @@ -115,7 +112,6 @@ def test_stata_writer_unicode(): # make sure to test with characters outside the latin-1 encoding pass -@dec.skipif(pandas_old) def test_genfromdta_datetime(): results = [(datetime(2006, 11, 19, 23, 13, 20), 1479596223000, datetime(2010, 1, 20), datetime(2010, 1, 8), datetime(2010, 1, 1), @@ -167,7 +163,6 @@ def test_date_converters(): assert_equal(_datetime_to_stata_elapsed( _stata_elapsed_date_to_datetime(i, "ty"), "ty"), i) -@dec.skipif(pandas_old) def test_datetime_roundtrip(): dta = np.array([(1, datetime(2010, 1, 1), 2), (2, datetime(2010, 2, 1), 3), diff --git a/statsmodels/nonparametric/tests/test_kde.py b/statsmodels/nonparametric/tests/test_kde.py index feb6649..b72ef26 100644 --- a/statsmodels/nonparametric/tests/test_kde.py +++ b/statsmodels/nonparametric/tests/test_kde.py @@ -72,7 +72,7 @@ class CheckKDE(object): # added it as test method to TestKDEGauss below # inDomain is not vectorized #kde_vals = self.res1.evaluate(self.res1.support) - kde_vals = [self.res1.evaluate(xi) for xi in self.res1.support] + kde_vals = [np.squeeze(self.res1.evaluate(xi)) for xi in self.res1.support] kde_vals = np.squeeze(kde_vals) #kde_vals is a "column_list" mask_valid = np.isfinite(kde_vals) # TODO: nans at the boundaries @@ -217,7 +217,7 @@ class CheckKDEWeights(object): def test_compare(self): xx = self.res1.support - kde_vals = [self.res1.evaluate(xi) for xi in xx] + kde_vals = [np.squeeze(self.res1.evaluate(xi)) for xi in xx] kde_vals = np.squeeze(kde_vals) #kde_vals is a "column_list" mask_valid = np.isfinite(kde_vals) # TODO: nans at the boundaries diff --git a/statsmodels/tsa/statespace/tests/test_mlemodel.py b/statsmodels/tsa/statespace/tests/test_mlemodel.py index d36ad82..cd332c4 100644 --- a/statsmodels/tsa/statespace/tests/test_mlemodel.py +++ b/statsmodels/tsa/statespace/tests/test_mlemodel.py @@ -660,7 +660,7 @@ def test_pandas_endog(): mod.filter([]) # Example : pandas.Series, string datatype - endog = pd.Series(['a'], index=dates) + endog = pd.Series(['a', 'b'], index=dates) # raises error due to direct type casting check in Statsmodels base classes assert_raises(ValueError, check_endog, endog, **kwargs) diff --git a/statsmodels/tsa/statespace/tests/test_representation.py b/statsmodels/tsa/statespace/tests/test_representation.py index 11734e3..91e918c 100644 --- a/statsmodels/tsa/statespace/tests/test_representation.py +++ b/statsmodels/tsa/statespace/tests/test_representation.py @@ -1033,8 +1033,8 @@ def test_simulate(): state_shocks) # ARMA(1,1): phi = [0.1], theta = [0.5], sigma^2 = 2 - phi = np.r_[0.1] - theta = np.r_[0.5] + phi = 0.1 + theta = 0.5 mod = sarimax.SARIMAX([0], order=(1,0,1)) mod.update(np.r_[phi, theta, sigma2]) diff --git a/statsmodels/tsa/statespace/tests/test_tools.py b/statsmodels/tsa/statespace/tests/test_tools.py index 941a34a..ede5d91 100644 --- a/statsmodels/tsa/statespace/tests/test_tools.py +++ b/statsmodels/tsa/statespace/tests/test_tools.py @@ -357,7 +357,7 @@ class TestConstrainStationaryMultivariate(object): cov = np.eye(unconstrained.shape[0]) constrained, _ = tools.constrain_stationary_multivariate(unconstrained, cov) companion = tools.companion_matrix( - [1] + [-constrained[i] for i in range(len(constrained))] + [1] + [-np.squeeze(constrained[i]) for i in range(len(constrained))] ).T assert_equal(np.max(np.abs(np.linalg.eigvals(companion))) < 1, True) -- 2.30.2